new Vue({
    el: '#app',
    data: {
        loading:false,
        loginForm:{ //登录表达数据源
            username:'',
            password:'',
            identiryCode:'',
        },
        codeImg:'/idcode' //验证码接口
    },

    methods: {
        //调用登录接口
        handleLogin() {
            this.loading = true
            let pwd = sha256.hmac(this.loginForm.username, this.loginForm.password)
            $.ajax({
                type: 'post',
                url: '/login',
                data: {
                    username:this.loginForm.username,
                    password:pwd,
                    identiryCode:this.loginForm.identiryCode,
                },
                dataType: 'json',
                success: (res, s, xhr) => {
                    if (res.code == 0) {
                        this.$message.success('登录成功')
                        //登录成功跳转到首页
                        window.location.href = "/";
                    } else {
                        this.$message.error(res.msg || '网络异常')
                    }
                    this.loading = false
                },
                error: (xhr, s, err) => {
                    console.log("wdy=",xhr, s, err)
                    this.$message.error(err.msg || '网络异常')
                    this.loading = false
                    return false;
                }
            });
        },
        //重新加载验证码
        reloadIdCode(){
            this.codeImg = this.codeImg +'?'+Math.random();
        }
    }
})
